<?php

// +----------------------------------------------------------------------
// | Static Plugin for ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2023 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/think-plugs-static
// | github 代码仓库：https://github.com/zoujingli/think-plugs-static
// +----------------------------------------------------------------------

namespace app\index\controller;

use think\admin\Controller;
use app\data\model\DataCat;
use app\data\model\DataDevice;
use app\data\service\IotThingService;
class Index extends Controller
{
    public function index()
    {
        $this->redirect(sysuri('admin/login/index'));
    }
    function send_cat_info($info,$del=0){

        $msg=[];
        if($info['sort']>0){
            $iotIds = DataDevice::mk()->where(['member_id'=>$info['member_id'],'status'=>1])->column('iotId');
            $weight = round($info['weight']/1000, 2);
            $class = new IotThingService();
            $avatar_thumb =$info['avatar_thumb'];
            $data=[
                'Cat_ID'=>$info['sort'],
                'Cat_Name'=>$info['nickname'],
                'Cat_Weight'=>$weight,
                'Cat_Picture_Size'=>$avatar_thumb==''?0:filesize($avatar_thumb),
                'Cat_Picture'=>$avatar_thumb==''?'':config('iot.host').str_replace('./', '/', $avatar_thumb),
                'Del_ID'=>$del,
            ];
            foreach($iotIds as $k=> $v){
                $res = $class->setService($v,'Cat_Data',json_encode($data));
                $msg[$k]=$res['data']->body->data;
                unset($res);
            }
        }
        return $msg;
    }
    public function test(){
       // SELECT * FROM `data_cat` WHERE sort>0;
        $res = DataCat::mk()->where('member_id','=',1)->where('sort','>',0)->where('is_deleted','=',0)->select()->toArray();
        foreach($res as $v){
            $data = $this->send_cat_info($v);
            var_dump($data);
        }
        exit;
        echo date('Y-m-d H:i:s',1715843752534/1000);exit;
        echo base64_decode('5L2g5aW977yM5LiW55WM77yB');exit;
// 中文字符串
        $chineseString = "你好，世界！";

// 确保字符串是UTF-8编码
        $encodedString = mb_convert_encoding($chineseString, 'UTF-8');

// 转换为Base64编码
        $base64EncodedString = base64_encode($encodedString);
        echo $base64EncodedString;
EXIT;
        $url = 'https://tatatest.dog8.cc/upload/ee/78216b31fbc78f96db8f2f3265d180.png';
        $path = parse_url($url,PHP_URL_PATH);
        echo $path;exit;
        $min = 0;
        $max = 100;
        $parts = 87;

        $range = range($min, $max, ($max-$min)/$parts);
        echo  json_encode(preserveTwoDecimalPlaces($range));exit;
        print_r($range);exit;
        print_r($range);

        exit;
        $str = '{}';
        $data = json_decode($str,true);
        $firstIndex = key($data);
       var_dump($firstIndex);
        exit;
        echo  sysconf('about.weight_min_max');
    }
}
